
package com.j2eefast.produce.pms.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.sys.entity.SysUserEntity;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import com.j2eefast.produce.pms.entity.PmsInspectionAccountEntity;
import com.j2eefast.produce.pms.entity.PmsParticipantEntity;
import com.j2eefast.produce.pms.entity.PmsProjectEntity;
import com.j2eefast.produce.pms.mapper.PmsInspectionAccountMapper;
import com.j2eefast.produce.pms.mapper.PmsParticipantMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>参建单位</p>
 *
 * @author: summer
 * @date: 2021-05-29 16:47
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */
@Service
@Transactional(readOnly = true)
public class PmsInspectionAccountService extends ServiceImpl<PmsInspectionAccountMapper, PmsInspectionAccountEntity> {

    @Resource
    protected PmsInspectionAccountMapper pmsInspectionAccountMapper;



	/**
	 * 页面展示查询翻页
	 */
	public PageUtil findPage(Map<String, Object> params) {
		String inspectionAccount = (String) params.get("inspectionAccount");
		String inspectionUnit = (String) params.get("inspectionUnit");
		String projectName = (String) params.get("projectName");
		String projectType = (String) params.get("projectType");
		String quota = (String) params.get("quota");
		String discount = (String) params.get("discount");
		String region = (String) params.get("region");
		String beginTime = (String) params.get("beginTime");
		String endTime = (String) params.get("endTime");
		String inspectionAccount2 = (String) params.get("inspectionAccount2");
		String inspectionUnit2 = (String) params.get("inspectionUnit2");
		Page<PmsInspectionAccountEntity> page = pmsInspectionAccountMapper.findPage(
				new Query<PmsInspectionAccountEntity>(params).getPage(),
				StrUtil.nullToDefault(inspectionAccount,""),
				StrUtil.nullToDefault(inspectionUnit,""),
				StrUtil.nullToDefault(projectName,""),
				StrUtil.nullToDefault(projectType,""),
				StrUtil.nullToDefault(quota,""),
				StrUtil.nullToDefault(discount,""),
				StrUtil.nullToDefault(region,""),
				StrUtil.nullToDefault(beginTime,""),
				StrUtil.nullToDefault(endTime,""),
				StrUtil.nullToDefault(inspectionAccount2,""),
				StrUtil.nullToDefault(inspectionUnit2,""),
				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}


    public List<PmsInspectionAccountEntity> findList(Map<String, Object> params) {
//        String testingIndustry = (String) params.get("testingIndustry");
        String inspectionUnit = (String) params.get("inspectionUnit");
        String projectName = (String) params.get("projectName");
        List<PmsInspectionAccountEntity> page = pmsInspectionAccountMapper.findList(
                new Query<PmsInspectionAccountEntity>(params).getPage(),
//                StrUtil.nullToDefault(testingIndustry, ""),
                StrUtil.nullToDefault(inspectionUnit, ""),
                StrUtil.nullToDefault(projectName, ""),
                (String) params.get(Constant.SQL_FILTER));
        return page;
    }




    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIds(Long[] ids) {

        return pmsInspectionAccountMapper.deleteByIds(ids);

    }

    @Transactional(rollbackFor = Exception.class)
    public boolean updateCheck(Long id) {
        Long userId = UserUtils.getUserInfo().getId();

        return pmsInspectionAccountMapper.updateCheck(id, userId);

    }

    public SysUserEntity getSysById(@Param("userId") Long userId) {
        return pmsInspectionAccountMapper.getSysById(userId);
    }


}
